﻿<cfscript>
/** 
* @hint "depTaskManager - 开课学院的教学任务操作是否具有相应的权限" 
*/ 

component 
	extends="MachII.framework.EventFilter" 
	displayname="acadmicManager.filters.senate.programTaskAccessFilter" 
	output=false 
	depends="sessionAdvice" 
	{
	
	/*
	* @hint "Configures this filter as part of the Mach-II framework" 
	*/
	public void function configure() output=false {} 
	
	/*
	* @hint "Filters event and returns a boolean to Mach-II indicating whether or not the event queue should proceed.  If not, the event queue is cleared and a new event is announced."
	* 
	* @event "MachII Event Object"
	* @eventContext "MachII EventContext Object"
	*/
	public boolean function filterEvent ( required MachII.framework.Event event, required MachII.framework.EventContext eventContext ) output=false {
		
		var depId = sessionAdvice.getUserProp("teacherDepartment");
		
		var sql = "SELECT 
						t_course.institute_id 
					FROM 
						t_task 
						INNER JOIN t_course ON t_course.cid = t_task.cid 
					WHERE 
						t_task.tsk_id = :taskId ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="taskId", value=event.getArg("TaskID", event.getArg("TSK")), cfsqltype="cf_sql_varchar" );
		rs_task = queryObj.execute( sql=sql ).getResult();
	
		if ( (rs_task.recordCount EQ 0) or depId eq "" ) {
			return false;
		}
		
		if (rs_task.institute_id eq depId) {
			/* 如果课程开课单位和会话用户单位相同 则继续操作 */
			return true;
		}
		else {
			/* 发送越权提醒 */
			announceEvent("programTaskAccessDenide", event.getArgs());
		}
		
		return false;
	}
	
}
</cfscript>